package com.boot2.core.scheduler;

import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;

import java.util.Map;

/**
 * @author zhangweilin
 * @Description: job公共
 * @date 2018/6/7
 */
public interface JobHandler {


    /**
     * 获取路由map
     *
     * @return
     */
    Map<String, ScheduleTaskHandler> getMap();

    /**
     * 公共部分
     *
     * @param jobExecutionContext
     */
    default void hand(JobExecutionContext jobExecutionContext) {
        JobDataMap mergedJobDataMap = jobExecutionContext.getMergedJobDataMap();
        String code = (String) mergedJobDataMap.get(SchedulerJobDataMapConsant.code);
        ScheduleTaskHandler handler = getMap().get(code);
        if (null == handler) {
            System.err.println("没有对应的handler,code: " + code);
            return;
        }
        JobExecutionContextHelper.updateSchedulerTaskFireTime(jobExecutionContext);
        handler.hand(jobExecutionContext);
    }
}
